var iot = require('iot');
var network = require('network');

var net = network.openNetWorkClient();

var productKey = 'productKey';      /* your productKey */
var deviceName = 'deviceName';      /* your deviceName */
var productSecret = 'productSecret';  /* your deviceSecret */

var device;

function dynRegDevice()
{
    iot.dynreg({
        productKey: productKey,
        deviceName: deviceName,
        productSecret: productSecret
    }, function(deviceSecret) {
        console.log('receive deviceSecret is ' + deviceSecret);
    });
}

var status = net.getStatus();
console.log('net status is: ' + status);

if (status == 'connect') {
    dynRegDevice();
} else {
    net.on('connect', function () {
        dynRegDevice();
    });
}